package com.example.cinema.controller;


import com.example.cinema.entity.*;
import com.example.cinema.mapper.OrderMapper;
import com.example.cinema.mapper.ScheduleMapper;
import com.yc.sign.web.bean.SignProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.SessionAttribute;

import javax.servlet.http.HttpSession;
import java.time.LocalDateTime;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yc138
 * @since 2024-08-26
 */
@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    ScheduleMapper scheduleMapper;
    @Autowired
    OrderMapper orderMapper;
    @Autowired
    SignProperties properties;
    @RequestMapping("querySchedule")
    public Schedule querySchedule(int sid){
        return scheduleMapper.findById(sid);
    }

    @RequestMapping("pay")
    @Transactional
    public Result pay(@RequestBody Orders order, HttpSession session){
        User user = (User) session.getAttribute(properties.getSessionKey());
        order.setUid(user.getId());
        order.setPayTime(LocalDateTime.now());
        order.setStatus(1);
        int insert = orderMapper.insert(order);
        if (insert <=0){
            return new Result(0,"支付失败",null);
        }
        return new Result(1,"支付成功",null);
    }
}



